var openid = "";
const app = getApp();
const db = wx.cloud.database();
Component({
    data: {
      selected: null,
      color: "#7A7E83",
      selectedColor: "#ff0000",
      list: [],
      message: 0
    },
    
    attached() {
        let that = this;
      this.setData({
          
        list: [
        {
            "text": "治愈卡片",
            "pagePath": "/pages/cureCard/cureCard",
            "iconPath": "/images/cureCard.png",
            "selectedIconPath": "/images/cureCard_selected.png"
        },{
            "text": "心间广场",
            "pagePath": "/pages/square/square",
            "iconPath": "/images/square.png",
            "selectedIconPath": "/images/square_selected.png"
        },{
            "bulge": true,
            "pagePath": "/pages/diary/diary",
            "iconPath": "/images/addDiary.png",
        },{
        "text": "心晴日历",
        "pagePath": "/pages/calendar/calendar",
        "iconPath": "/images/calendar.png",
        "selectedIconPath": "/images/calendar_selected.png"
        },{
            "text": "我",
            "pagePath": "/pages/myself/myself",
            "iconPath": "/images/myself.png",
            "selectedIconPath": "/images/myself_selected.png"
        }]
      })
    },
    methods: {
      switchTab(e) {
          const that = this;
        const data = e.currentTarget.dataset
        const url = data.path
        if ( data.index != 2 ) {
            wx.switchTab({
                url: url,
                success: function(res){
                    that.setData({
                        message: app.globalData.message
                    })
                },
                fail: res => {
                    console.log(res)
                },
            });
        }
        else {
            let today = getApp().globalData.date;
            console.log(today);
            openid = getApp().globalData.openid
            
            wx.navigateTo({
                url: '../diary/diary',
                success: function(res) {
                    res.eventChannel.emit('acceptDataFromOpenerPage',{year:today.getFullYear(),month:today.getMonth()+1,day:today.getDate(),emoji:"愉悦",authorid:openid,publish:false,fixmode: true,visit: false});
                }
            })
        }
        this.setData({
            message: app.globalData.message
        })
      }
    }
  })
  